package pfc.pfcjoc.core;

import static playn.core.PlayN.*;

import org.jbox2d.common.Vec2;

import playn.core.Game;

public class pfcjoc implements Game {
  public static int width = 800;
  public static int height = 600;
  private GameLogic gameLogic;
  private static final float pixelsInAPhysicUnit = 33.33333f;


  // 1 / 33.33333f = 800pixels/24physUnits = 600pixels/18physUnits
  public static Vec2 toPix(Vec2 phy) {
    Vec2 pix = new Vec2(phy.x * pixelsInAPhysicUnit, phy.y * pixelsInAPhysicUnit);
    return pix;
  }


  public static Vec2 toPhy(Vec2 pix) {
    Vec2 phy = new Vec2(pix.x / pixelsInAPhysicUnit, pix.y / pixelsInAPhysicUnit);
    return phy;
  }


  public static float toPix(float phy) {
    return phy * pixelsInAPhysicUnit;
  }


  public static float toPhy(float pix) {
    return pix / pixelsInAPhysicUnit;
  }


  public static void printVec2(String msg, Vec2 v) {
    log().info(msg + " x: " + v.x + " y: " + v.y);
  }


  @Override
  public void init() {
    // MIDA FINESTRA
    graphics().setSize(width, height);

    gameLogic = new GameLogic();
  }


  @Override
  public void paint(float alpha) {
    gameLogic.paint(alpha);
  }


  @Override
  public void update(float delta) {
    gameLogic.update(delta);
  }


  @Override
  public int updateRate() {
    return 25;
  }
}
